import sys
import os

# ===== ===== ===== ===== ===== =====
# 运行环境设置
# ===== ===== ===== ===== ===== =====

# 一些项目中的python代码被设计为库代码, 因此需要将其加入环境变量.
# 比起脚本的方式, 直接加入sys.path的方式可以同时适应windows和linux系统,
# 当然也有劣势, 就是所有代码都必须import settings才能使用项目内的库代码.
# 或许virtualenv会是个更优雅的解决方案, 但是需要更多的配置和依赖(其实我
# 不会用才是最主要的原因). 采用当前的做法, 虽然冗重, 但是在新的机器上几乎
# 不用配置即可运行, 非常有利于比赛中共享代码.

# 通过本文件(settings.py)的位置构造出项目根目录的路径(git仓库的目录)
# PROJ_BASE = r'C:\_AAA\BlueNet\GK2020\design'
# PROJ_BASE = r'/mnt/winshare'
PROJ_BASE = os.path.abspath(__file__)  # 获得settings.py(本文件)的绝对路径
PROJ_BASE = os.path.dirname(PROJ_BASE) # 从路径中析出目录
PROJ_BASE = os.path.join(PROJ_BASE, os.path.pardir)  # 相对的父目录
PROJ_BASE = os.path.abspath(PROJ_BASE)  # 绝对的父目录


# 把相关包所在的目录加入搜索路径
sys.path.append(os.path.join(PROJ_BASE, r'communication/python'))  # (简单的)通信协议库
sys.path.append(os.path.join(PROJ_BASE, r'visual'))  # 可视化工具
sys.path.append(os.path.join(PROJ_BASE, r'robot'))   # 机器人项目
sys.path.append(os.path.join(PROJ_BASE, r'robot/control'))   
sys.path.append(os.path.join(PROJ_BASE, r'robot/vision'))   


# ===== ===== ===== ===== ===== =====
# 运行时参数文件存储路径设置
# ===== ===== ===== ===== ===== =====
# linux 下用smba测试时, 通常只开放共享文件夹的读权限以避免误修改, 此时
# 将 /dev/shm 作为临时目录, 储存参数文件以便测试.
DIR_PARAMS = os.path.join(PROJ_BASE, r'robot')
if not os.access(DIR_PARAMS, os.W_OK):
    DIR_PARAMS = r'/dev/shm'
print('settings: use path "%s" to store params file' % DIR_PARAMS)

PTH_PARAMS_VISION = os.path.join(DIR_PARAMS, r'params_vision.json')


# ===== ===== ===== ===== ===== =====
# 运行时参数的 name
# ===== ===== ===== ===== ===== =====
# 本来觉得没必要多此一举,直接传字符串就好了,但是考虑了下发现,
# 字符串不慎写错一个字母, 程序不会报错, 运行出了问题很难调, 但是变量名
# 写错,程序就会报错,一开始就能发现问题. 所以最终还是采用这个多此一举又
# 有点麻烦的方法.
NAME_PARAMS_BKPJ = 'params_bkpj'
NAME_PARAMS_RUNTIME = 'params_runtime'


# ===== ===== ===== ===== ===== =====
# 音频文件的位置
# ===== ===== ===== ===== ===== =====
DIR_SND = os.path.join(PROJ_BASE, r'resources', r'audio')
PTH_SND_LD_1 = os.path.join(DIR_SND,  '汉语男-LoadStuff1.wav')
PTH_SND_LD_2 = os.path.join(DIR_SND,  '汉语男-LoadStuff2.wav')
PTH_SND_ARV_1 = os.path.join(DIR_SND, '汉语男-Arrive1.wav')
PTH_SND_ARV_2 = os.path.join(DIR_SND, '汉语男-Arrive2.wav')
PTH_SND_ULD_1 = os.path.join(DIR_SND, '汉语男-UnloadStuff1.wav')
PTH_SND_ULD_2 = os.path.join(DIR_SND, '汉语男-UnloadStuff2.wav')
PTH_SND_WRG_CODE = os.path.join(DIR_SND, 'WrongCode.wav')
PTH_MUSIC_WWW = os.path.join(DIR_SND, '洒水车-生日快乐.mp3')


# ===== ===== ===== ===== ===== =====
# 与MCU交互的指令及数据定义
# ===== ===== ===== ===== ===== =====
# LB stands for Label; V stands for Value
# === 一般指令 ===
LB_OK = 'OK'
LB_ERR = 'ERR'

# ===  扫描二维码 ===
LB_SCAN_QR = 'ScanQR'   # cmd
LB_RSLT_QR = 'qr'       # data
V_QR_1 = 1
V_QR_2 = 2

# === 发出语音 ===
LB_SND = 'PlaySound'      # cmd
V_SND_LOAD = 1            # 语音种类
V_SND_ARRIVE = 2
V_SND_UNLOAD = 3
V_SND_WRONG_CODE = 4      # 收获码错误

# === 交通识别 ===
LB_GO = 'Go'            # cmd
LB_SCAN_TF = 'ScanTF'   # scan traffic light

LB_TF_CHANGED = 'tf_changed'  # 交通灯发生变化
LB_TF = 'tf_light'           # data
V_TF_RED = 1
V_TF_YELLOW = 2
V_TF_GREEN = 3


# === 控制输出 ===
LB_MOVE = 'Move'    # cmd
V_MV_ERR = 0
V_MV_TURN_LEFT  = 1
V_MV_TURN_RIGHT = 2
V_MV_NO_CHANGE  = 3







